<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('优惠卷信息列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
    <div class="toolbar" id="toolbar" role="group">
        <form id="formId" class="form-inline">
            <input type="text" class="form-control mr-1" name="cardCode" placeholder="请输入卡编号...">
            <select name="status" class="form-control mr-1" th:with="type=${@dict.getType('qdx_card_code_status')}">
                <option value="">状态</option>
                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
            </select>
            <button type="button" class="btn btn-primary mr-1" onclick="$.table.search()">
                <i class="fa fa-search"></i>
                搜索
            </button>
            <button type="button" class="btn btn-default" onclick="$.form.reset()">
                <i class="fa fa-refresh"></i>
                重置
            </button>
        </form>
    </div>
    <table id="bootstrap-table" class="table-striped"></table>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
    var sta = [[${@dict.getType('qdx_card_code_status')}]];
    var cardId = [[${cardId}]];
    $(function() {
        var options = {
            url: "/card/course/info/list.json?cardId="+cardId,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            modalName: "优惠卷信息",
            columns: [
                {
                    field: 'id',
                    title: 'id'
                },
                {
                    field: 'cardCode',
                    title: '卡编号'
                },
                {
                    field: 'cardCodePassword',
                    title: '密码'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(sta, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status == "INIT"){
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="closeCard(\'' + row.id + '\',\'' +'CLOSE'+ '\')"><i class="fa fa-remove"></i>作废</a> ');
                        }else if(row.status == "CLOSE"){
                            actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="closeCard(\'' + row.id + '\',\'' +'INIT'+ '\')"><i class="fa fa-mail-reply-all"></i>恢复</a>');
                        }
                        if(row.status == "OVERDUE"){
                            actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" disabled="">逾期</a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //作废或恢复
    function closeCard(id,sta) {
        table.set();
        var str ="";
        if(sta=="CLOSE"){
            str = "确定执行作废此卡"
        }else{
            str = "确定执行恢复此卡"
        }
        $.modal.confirm(str, function() {
            var data = {"id":id,"status": sta };
            $.operate.submit("/card/close.json", "post", "json", data);
        });
    }
</script>
</body>
</html>